{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import cv2 as cv"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "img = cv.imread('/Users/liudaheng/Desktop/AI/data/lena.jpg')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "cv.imshow(\"Hello World!\", img)\n",
    "cv.waitKey()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "hsv = cv.cvtColor(img, cv.COLOR_BGR2HSV)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "115"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cv.imshow(\"Hue\", hsv[:, :, 0])\n",
    "cv.imshow(\"Saturation\", hsv[:, :, 1])\n",
    "cv.imshow(\"Value\", hsv[:, :, 2])\n",
    "cv.waitKey()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 对HSV的解释\n",
    "\n",
    "##### Hue\n",
    "Hue是颜色。对比原图，我们可以看到原图中颜色偏红色的地方（暖色），在Hue里面是深色的，也就是数值接近于0，相反，原图偏冷色或偏紫，黑的地方，Hue是偏白色的，数值接近于255.\n",
    "\n",
    "##### Saturation\n",
    "这里是饱和度。在眼睛附近颜色比较鲜艳，帽子上的羽毛装饰也比较鲜艳，对应的Saturation是比较高的，颜色偏白，数值靠近255。相反，帽子右边颜色比较淡，饱和度低，所以对应的saturation偏黑，数值较低。整体饱和度比较均匀。\n",
    "\n",
    "##### Value\n",
    "这里是亮度。原理相近，明亮的地方亮度高，对应的颜色比较白，数值高，反之亦然。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "115"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cv.imshow(\"Blue\", img[:, :, 0])\n",
    "cv.imshow(\"Green\", img[:, :, 1])\n",
    "cv.imshow(\"Red\", img[:, :, 2])\n",
    "cv.waitKey()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 对BGR的解释\n",
    "\n",
    "##### Red\n",
    "与HSV类似，黑色数值低，白色数值高。Red里面整体偏白，代表原图整体偏红。\n",
    "\n",
    "##### Blue，Green\n",
    "同理，我们可以看到Blue中的羽毛装饰亮度比Green中的要高，所以Blue在这里面的占比较高。而高的Red，较高的Blue和少量的Green可以组合成原图中的紫色。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "cv.waitKey()\n",
    "cv.destroyAllWindows()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
